<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

/**
 * 扫码支付
 */
class Scan
{
	public static function scanDo()
	{
		$db     = new Datebase();

		$config = new Config();

		$param  = $db->param();

		// 订单号
		$param['orderNumber'] = 'C' . time() . 'U' . $param['uid'];

		$param['paytype'] = Config::$folder.'-'.Config::$merchant;
		// 数据检测
		// $verifyRes = $db->verifyScan($param);

		// if ($verifyRes != 'Y') $db->ajaxReturn($verifyRes);

		$data = [
			'bid'         => (int) Config::$merchant,
			'money'       => (float) sprintf("%.2f", $param['price']),
			'order_sn'    => (string) $param['orderNumber'],
			'notify_url'  => (string) base64_encode(Config::$notifyUrl),
			'notify_base' => (int) 1,
			'pay_type'    => (int) $param['scanType'],
			'is_pc'       => (int) 2,
			'userid'      => (string) $param['uid'],
			'data_type'   => (string) 'url',
		];

		$data['sign'] = Config::getSign($data);

		$curlRes = Config::curl(Config::$api . 'api/index', $data);

		if (!$curlRes) $db->ajaxReturn($resArray['通道不足']);

		$resArray = json_decode($curlRes, true);

		if ($resArray['code'] != '100') $db->ajaxReturn($resArray['msg']);

		$db->ajaxReturn($resArray['data']['url']);
	}
}

Scan::scanDo();
